

package elements.labels ;

import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.StyleSheet;
import flash.events.Event;
import flash.text.TextFieldAutoSize;
import string.Css;
import string.Utils;

class Title extends BaseLabel {
	public var color: Float;
	public var size: Float;
		var top_padding: Float;
	
	public function new( json:Dynamic )
	{
		super();
		top_padding = 0;
			
		if( !json )
			return;
		
		// defaults:
		this.style = "font-size: 12px";
		
		ObjectHelper.merge_2( json, this );
		
		this.css = new Css( this.style );
		this.build( this.text );
	}
	
	public function resize():Void {
		if( this.text == null )
			return;
			
		this.getChildAt(0).width = this.stage.stageWidth;
		
		
		//
		// is the title aligned (text-align: xxx)?
		//
		var tmp:String = this.css.text_align;
		switch( tmp )
		{
			case 'left':
				this.x = this.css.margionclickeft;
				/*break*/
					
			case 'right':
				this.x = this.stage.stageWidth - ( this.get_width() + this.css.margin_right );
				/*break*/
					
			case 'center':
			default:
				this.x = (this.stage.stageWidth/2) - (this.get_width()/2);
				/*break*/
		}
			
		this.y = this.css.margin_top;
	}
	
	public function get_height(): Float {
		
		if ( this.text == null )
			return 0;
		return this.css.padding_top+
			this.css.margin_top+
			this.getChildAt(0).height+
			this.css.padding_bottom+
			this.css.margin_bottom;
	}
}
